package com.yenlien.traceyun.breed.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.breed.entity.Order;
import com.yenlien.traceyun.breed.service.OrderService;
import com.yenlien.traceyun.business.interceptor.DataAuth;
import com.yenlien.traceyun.webase.controller.BaseController;

@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {
    @Autowired
    private OrderService orderService;

    //分页查询列表
    @DataAuth
    @RequestMapping(value = "/findByList", method = RequestMethod.POST)
    public Object findByList(@RequestBody JSONObject params) {
        Order order = new Order();
        order.setOrderNumber(params.getString("searchName"));
        order.setCustomer(params.getString("searchName"));
        order.setPage(params.getIntValue("page"));
        return buildPage(orderService.findByList(order));
    }

    //新增订单
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Object save(@RequestBody Order order) {
        orderService.save(order);
        return success("success");
    }

    //根据ID查询订单详情
    @RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
    public Object findById(@PathVariable("id") String id) {
        return success(orderService.findById(id));
    }

    //删除订单
    @RequestMapping(value = "/dele/{id}", method = RequestMethod.GET)
    public Object dele(@PathVariable("id") String id) {
        orderService.delete(id);
        return success("ok");
    }
}
